package com.zh.po;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@TableName("person")
@Data
public class PersonPo {

    public String id;

    public String name;

    public Integer sex;

    public static void main(String[] args) {
        PersonPo po = new PersonPo();
        po.setSex(1);
        po.setName("sss");
        po.setId("22");

        Class<? extends PersonPo> aClass = po.getClass();
        Field name = null;
        try {
            name = aClass.getDeclaredField("name");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        try {
            Object o = name.get(po);
            System.out.println(o);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            String m_name = declaredMethod.getName();
           // System.out.println(m_name);
            if(m_name.equals("getName")){
                Object invoke = null;
                try {
                    invoke = declaredMethod.invoke(po);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
                System.out.println(invoke);
            }
        }


    }
    public String name(){
        return "A";
    }

    public String name(String in){
        return in;
    }
}
